(function($) {
    appcan.button("#return", "btn-act",
    function() {
        appcan.window.close(-1);
        appcan.window.open({
            name:'personal',
            data:'personal.html'
        });
    });
    appcan.button("#nav-right", "btn-act",
    function() {});
    
    //选择拍照或相册,为修改元素添加单击事件
    appcan.button("#touxiang", "btn-act",
    function() {
        uexCamera.cbPick = function(opCode, dataType, data) {
            if (dataType == 0) {
                addPic(data);
            }
            else{
                appcan.window.openToast("请选择图片", '2000', '5', 0);
            }
        }
        uexCamera.open();
    });
        /*从相册选择*/
        function getPic() {
            uexImageBrowser.cbPick = function(opCode, dataType, data) {
                if (dataType == 0) {
                    addPic(data);
                }
            }
            uexImageBrowser.pick();
        }
        //把选择的图片设置到头像位置
        function addPic(data) {
            appcan.logs("截图头像后的路径:" + data);
            $("#touxiang").css("background-image", "url('" + data + "') !important");
           // appcan.window.publish('imgData',data);
            uploadFile(data, function(serverUrl) {
                serverImgID = serverUrl;
                alert('上传图片返回路劲'+serverImgID)
                appcan.locStorage.setVal("imgID", serverImgID);
            });
        }

    appcan.ready(function() {
        //提交编辑的个人信息
        appcan.button("#submit", "btn-act", function() {
            var newName = $("#newName").val();
            var pwd = $("#npwd").val();
            var r_pwd = $("#r_npwd").val();
            if (!isDefine(pwd)) {
                appcan.window.openToast("请输入新密码！", '2000', '5', 0);
                return;
            }
            if (!isDefine(r_pwd)) {
                appcan.window.openToast("请输入确认密码！", '2000', '5', 0);
                return;
            }
            if(pwd!=r_pwd){
                appcan.window.openToast("两次密码输入不一致！", '2000', '5', 0);
                return;
            }else{
                 appcan.window.openToast("修改成功", 500, 5);
                 appcan.locStorage.setVal('uname',newName);
                 
                 //alert('要去personal页面');
                 appcan.window.close(-1);
                 appcan.window.open({  
                           name:'personal',
                           data:'personal.html'
                       });
            }
             appcan.locStorage.setVal('yemian','xiugai'); 
            // alert(appcan.locStorage.val('uname'));
         });
         //一定要加上这个函数的定义
        function isDefine(para) {
          if ( typeof para == 'undefined' || para == "" || para == null || para == undefined || para == 'undefined')
            return false;
          else
            return true;
        }
        
        $.scrollbox($("body")).on("releaseToReload",
        function() { //After Release or call reload function,we reset the bounce
            $("#ScrollContent").trigger("reload", this);
        }).on("onReloading",
        function(a) { //if onreloading status, drag will trigger this event
        }).on("dragToReload",
        function() { //drag over 30% of bounce height,will trigger this event
        }).on("draging",
        function(status) { //on draging, this event will be triggered.
        }).on("release",
        function() { //on draging, this event will be triggered.
        }).on("scrollbottom",
        function() { //on scroll bottom,this event will be triggered.you should get data from server
            $("#ScrollContent").trigger("more", this);
        }).hide();
    })

	
})($);